import React from 'react';
import PropTypes from 'prop-types'

class TodoItem extends React.Component {
    constructor(props) {
        super(props)
        this.state = {

        }
    }
    render() {
        const { item, test } = this.props
        return <div className='item' onClick={this.handleClick}>{test}-{item}</div>
    }
    handleClick = () => {
        // alert(this.props.index)
        const { deleteItem, index } = this.props
        deleteItem(index)
    }
}
TodoItem.propTypes = {
    test: PropTypes.string.isRequired,//isRequired代表必须要传
    item: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string
    ]),
    deleteItem: PropTypes.func,
    index: PropTypes.number
}

TodoItem.defaultProps = {
    test: 'hello world'
}

export default TodoItem